# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgbase=gmp
pkgname=('gmp' 'gmp-devel')
pkgver=6.1.2
pkgrel=1
pkgdesc="A free library for arbitrary precision arithmetic"
groups=('libraries')
arch=('i686' 'x86_64')
url="https://gmplib.org/"
license=('LGPL3')
install=gmp.install
source=(https://gmplib.org/download/gmp-${pkgver}/gmp-${pkgver}.tar.xz{,.sig}
        gmp-5.1.2-msys2.patch)
sha256sums=('87b565e89a9a684fe4ebeeddb8399dce2599f9c9049854ca8c0dfbdea0e21912'
            'SKIP'
            'c1ff80a8643a362f44be680a5430dca6f4ec16d84a4068d344a24b8d181e5436')
validpgpkeys=('5972C48224C1E7E62AA0275D1150EE33C1A000B0')   # Marco Bodrato

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/gmp-5.1.2-msys2.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --enable-cxx \
    --enable-fat \
    --enable-shared --disable-static
  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check
}

package_gmp() {
  mkdir -p ${pkgdir}/usr
  cp -rf $srcdir/dest/usr/bin ${pkgdir}/usr/
  cp -rf $srcdir/dest/usr/share ${pkgdir}/usr/
}

package_gmp-devel() {
  groups=('development')
  options=(staticlibs)
  depends=("gmp=${pkgver}")
  pkgdesc="GMP headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf $srcdir/dest/usr/include ${pkgdir}/usr/
  cp -rf $srcdir/dest/usr/lib ${pkgdir}/usr/
}
